package com.example.webapp.controller;

import com.example.webapp.entity.RequestHistory;
import com.example.webapp.service.HttpRequestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/request")
public class HttpRequestController {

    @Autowired
    private HttpRequestService httpRequestService;

    @GetMapping("/history")
    public ResponseEntity<Page<RequestHistory>> getHistory(
            @RequestParam(required = false) String url,
            @RequestParam(required = false) String method,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size) {
        
        return ResponseEntity.ok(httpRequestService.getRequestHistory(
            url, method, PageRequest.of(page, size)));
    }
} 